
//--------------------------------------------------------------------//
//     此代码由T4模板自动生成										  //
//	   生成时间 2020-08-22 14:34:39 	                              //
//	   描述：定时任务
//--------------------------------------------------------------------//

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using RayD.Core;

namespace RayD.Repository.Entites.SystemModule
{	
    [Table("BASE_JOB")]
	public class JobEntity 
	{
        #region 实体成员
		/// <summary>
		/// Id
		/// </summary>
		/// <returns></returns>
		[Key]
		[Column("B_ID")]
		public string B_Id { get; set; }
		/// <summary>
		/// CRON表达式
		/// </summary>
		/// <returns></returns>
		[Column("B_CRON")]
		public string B_Cron { get; set; }
		/// <summary>
		/// 任务名称
		/// </summary>
		/// <returns></returns>
		[Column("B_JOBNAME")]
		public string B_JobName { get; set; }
		/// <summary>
		/// 任务执行方式0：本地任务；1：外部接口任务
		/// </summary>
		/// <returns></returns>
		[Column("B_JOBTYPE")]
		public int? B_JobType { get; set; }
		/// <summary>
		/// 任务地址
		/// </summary>
		/// <returns></returns>
		[Column("B_JOBCALL")]
		public string B_JobCall { get; set; }
		/// <summary>
		/// 任务参数，JSON格式
		/// </summary>
		/// <returns></returns>
		[Column("B_JOBCALLPARAMS")]
		public string B_JobCallParams { get; set; }
		/// <summary>
		/// 任务执行终端（0：默认端）具体终端在数据字典中定义
		/// </summary>
		/// <returns></returns>
		[Column("B_JOBTERMINAL")]
		public JobTerminal? B_JobTerminal { get; set; }
		/// <summary>
		/// 备注
		/// </summary>
		/// <returns></returns>
		[Column("B_REMARK")]
		public string B_Remark { get; set; }
		/// <summary>
		/// 任务执行次数
		/// </summary>
		/// <returns></returns>
		[Column("B_RUNCOUNT")]
		public int? B_RunCount { get; set; }
		/// <summary>
		/// 异常次数
		/// </summary>
		/// <returns></returns>
		[Column("B_ERRORCOUNT")]
		public int? B_ErrorCount { get; set; }
		/// <summary>
		/// 下次执行时间
		/// </summary>
		/// <returns></returns>
		[Column("B_NEXTRUNTIME")]
		public DateTime? B_NextRunTime { get; set; }
		/// <summary>
		/// 最后一次执行时间
		/// </summary>
		/// <returns></returns>
		[Column("B_LASTRUNTIME")]
		public DateTime? B_LastRunTime { get; set; }
		/// <summary>
		/// 最后一次失败时间
		/// </summary>
		/// <returns></returns>
		[Column("B_LASTERRORTIME")]
		public DateTime? B_LastErrorTime { get; set; }
		/// <summary>
		/// 任务运行状态（0：停止，1：正在运行）
		/// </summary>
		/// <returns></returns>
		[Column("B_ENABLEDMARK")]
		public EnabledMark? B_EnabledMark { get; set; }
		/// <summary>
		/// 创建时间
		/// </summary>
		/// <returns></returns>
		[Column("B_CREATEDATE")]
		public DateTime? B_CreateDate { get; set; }
		/// <summary>
		/// 创建人ID
		/// </summary>
		/// <returns></returns>
		[Column("B_CREATEUSERID")]
		public string B_CreateUserId { get; set; }
		/// <summary>
		/// 创建人
		/// </summary>
		/// <returns></returns>
		[Column("B_CREATEUSERNAME")]
		public string B_CreateUserName { get; set; }
		/// <summary>
		/// 最后更新时间
		/// </summary>
		/// <returns></returns>
		[Column("B_MODIFYDATE")]
		public DateTime? B_ModifyDate { get; set; }
		/// <summary>
		/// 最后更新人ID
		/// </summary>
		/// <returns></returns>
		[Column("B_MODIFYUSERID")]
		public string B_ModifyUserId { get; set; }
		/// <summary>
		/// 最后更新人
		/// </summary>
		/// <returns></returns>
		[Column("B_MODIFYUSERNAME")]
		public string B_ModifyUserName { get; set; }
 
        #endregion
		
        #region 扩展操作
		/// <summary>
        /// 新增调用
        /// </summary>
        public void Create()
        {
			UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
			this.B_Id = Guid.NewGuid().ToString();
			if (this.B_EnabledMark.IsEmpty())
			{
				this.B_EnabledMark = EnabledMark.Disabled;
			}
			this.B_CreateDate = DateTime.Now.ToCstTime();
			this.B_CreateUserId = userInfo.userId;
			this.B_CreateUserName = userInfo.realName;
			this.B_ModifyDate = DateTime.Now.ToCstTime();
			this.B_ModifyUserId = userInfo.userId;
			this.B_ModifyUserName = userInfo.realName;
			this.B_RunCount = 0;
			this.B_ErrorCount = 0;
		}
        /// <summary>
        /// 编辑调用
        /// </summary>
        public void Modify()
        {
			UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
			this.B_ModifyDate = DateTime.Now.ToCstTime();
			this.B_ModifyUserId = userInfo.userId;
			this.B_ModifyUserName = userInfo.realName;
        }
        #endregion


    }
}
